package sample.plugin.di;

import android.app.Activity;
import android.widget.Toast;

import com.rapid.api.component.widget.tree.TreeItemViewHolder;
import com.rapid.api.framework.DataKeys;
import com.rapid.api.framework.project.file.ProjectFileUiEvent;
import com.rapid.api.project.structure.PSObject;
import com.rapid.api.project.structure.TreeNode;
import com.rapid.framework.data.Key;
import com.rapid.framework.extension.annotation.Import;
import com.rapid.framework.extension.assembly.DIObserver;

/**
 * 本类实现 DIObserver 接口以监听依赖重注入过程
 */
public class DIListening implements ProjectFileUiEvent, DIObserver {
    // 依赖Activity，当Activity发生变化时会重新注入
    @Import
    Activity activity;

    // 监听到发生了依赖重注入,当前类依赖了Activity
    // Activity改变时就会重新将新的Activity注入到变量
    @Override
    public void onDIHappened(Key<?> key, Object o) {
        if (key == DataKeys.ACTIVITY) {
            Toast.makeText(activity, "Activity改变: " + activity, Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onBindView(TreeItemViewHolder treeItemViewHolder, TreeNode<PSObject> treeNode) {

    }
}
